home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / CBGRX103.ZIP / contrib / libgrx / src / p4init.c < prev    next >
Text File  |  1993-12-06  |  3KB  |  80 lines

  1. /** 
  2.  ** P4INIT.C 
  3.  **
  4.  **  Copyright (C) 1992, Csaba Biegl
  5.  **    820 Stirrup Dr, Nashville, TN, 37221
  6.  **    csaba@vuse.vanderbilt.edu
  7.  **
  8.  **  This file is distributed under the terms listed in the document
  9.  **  "copying.cb", available from the author at the address above.
  10.  **  A copy of "copying.cb" should accompany this file; if not, a copy
  11.  **  should be available from where this file was obtained.  This file
  12.  **  may not be distributed without a verbatim copy of "copying.cb".
  13.  **  You should also have received a copy of the GNU General Public
  14.  **  License along with this program (it is in the file "copying");
  15.  **  if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  16.  **  Cambridge, MA 02139, USA.
  17.  **
  18.  **  This program is distributed in the hope that it will be useful,
  19.  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  **  GNU General Public License for more details.
  22.  **/
  23.  
  24. #include "p4.h"
  25. #include "gmalloc.h"
  26. #include "grdriver.h"
  27.  
  28. int _GrP4ModeReg;            /* saved bits of mode register */
  29.  
  30. /*
  31.  * VGA write operations table -- map our color flags to the EGA/VGA
  32.  * function selection register values
  33.  */
  34. int _GrP4WriteOps[] = {
  35.     (VGA_FUNC_SET << 8) + VGA_ROT_FN_SEL_REG,       /* C_SET */
  36.     (VGA_FUNC_XOR << 8) + VGA_ROT_FN_SEL_REG,       /* C_XOR */
  37.     (VGA_FUNC_OR  << 8) + VGA_ROT_FN_SEL_REG,       /* C_OR  */
  38.     (VGA_FUNC_AND << 8) + VGA_ROT_FN_SEL_REG       /* C_AND */
  39. };
  40.  
  41. /*
  42.  * An element of this table gets XOR-ed with the significant bits of
  43.  * the color. It has to be drawn only if the result is nonzero
  44.  */
  45. int _GrP4DrawTable[4] = {
  46.     ~C_SIGNIF,        /* C_SET -- always draw */
  47.     0,            /* C_XOR -- draw only if non-zero */
  48.     0,            /* C_OR  -- draw only if non-zero */
  49.     C_SIGNIF        /* C_AND -- draw only if not all 1-s */
  50. };
  51.  
  52.  
  53. void _GrP4Init(int memsize)
  54. {
  55.     char far *start;
  56.     long total,used;
  57.  
  58.     _GetVGAModeMask();
  59.     _SetVGAWriteMode(0);
  60.     _SetVGAWriteAllPlanes();
  61.     _SetVGASetResetPlanes(0x0f);
  62.     used = ((long)_GrScreenX * (long)_GrScreenY) / 8L;
  63.     switch(memsize) {
  64.         case GRD_64K:   total = 0x10000L  / 8L; break;
  65.         case GRD_128K:  total = 0x20000L  / 8L; break;
  66.         case GRD_256K:  total = 0x40000L  / 8L; break;
  67.         case GRD_512K:  total = 0x80000L  / 8L; break;
  68.         case GRD_1024K: total = 0x100000L / 8L; break;
  69.         default:        for(total = 1L; total < used; total <<= 1);
  70.     }
  71. #ifdef _MAXVIDPLANESIZE
  72.     if(total > _MAXVIDPLANESIZE) total = _MAXVIDPLANESIZE;
  73. #endif
  74.     if(!_GrBigFrameBuffer && (total >= 0x10000L)) total = 0x10000L;
  75.     if((total -= used) < 0L) total = 0L;
  76.     start = (char far *)((char huge *)_GrVidPage.gc_baseaddr + used);
  77.     _GrVidMemInit(start,(unsigned int)total);
  78. }
  79.  
  80.